<%@ page language="java" %>

<%@ page import="java.util.*,
                 com.broadvision.web.util.ViewDynaBean,
                 org.apache.commons.beanutils.PropertyUtils"
%>

<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 

<script language="JavaScript">
   function doAttachment(theForm,value){
     theForm.filePath.value=value;
     var theURL="/contentAttachDetail.do";
     theForm.action='<html:rewrite page="'+theURL+'" />';
     theForm.submit();
     return true;
   }
</script>


<jsp:useBean id="searchResultView" scope="request" type="com.broadvision.web.util.ViewDynaBean"/> 
<bean:size id="resultSize" name="searchResultView" property="resultList"/>

<% 
   String ctxPath = request.getContextPath(); 
   ViewDynaBean view = (ViewDynaBean) request.getAttribute("searchResultView"); 
   Integer totalCount = (Integer) PropertyUtils.getSimpleProperty(view, "totalCount");
   String totalCountNum = "0";
   if (totalCount != null)
       totalCountNum = totalCount.toString();
%>

<script language="javascript" src="<%=request.getContextPath()%>/cs/js/date.js"></script>
<script language="javascript" src="<%=request.getContextPath()%>/cs/js/user_popup_funcs.js"></script>

<script language="javascript">

function isAllDigits(argvalue) {
   argvalue = argvalue.toString();
   var validChars = "0123456789";
   var startFrom = 0;

   if (argvalue.length==0)
     return false;
   for (var n = startFrom; n < argvalue.length; n++) {
       if (validChars.indexOf(argvalue.substring(n, n+1)) == -1) return false;
   }
   return true;
}

function validateForm(myform, formname) {
  if (myform.includeCreateDateStart.checked) {
    var date = getDateOnly(formname, "createDateStart");
    if (null == date) {
      alert('<bean:message bundle="appCommonRes" key="bp.process.processInstanceSearch.error.launchDateStart"/>');
      return false;
    }
  }

  if (myform.includeCreateDateEnd.checked) {
    var date = getDateOnly(formname, "createDateEnd");
    if (null == date) {
      alert('<bean:message bundle="appCommonRes"  bundle="appCommonRes" key="bp.process.processInstanceSearch.error.launchDateEnd"/>');
      return false;
    }
  }

  if (myform.includeModDateStart.checked) {
    var date = getDateOnly(formname, "modDateStart");
    if (null == date) {
      alert('<bean:message bundle="appCommonRes"  bundle="appCommonRes" key="bp.process.processInstanceSearch.error.dueDateStart"/>');
      return false;
    }
  }

  if (myform.includeModDateEnd.checked) {
    var date = getDateOnly(formname, "modDateEnd");
    if (null == date) {
      alert('<bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.error.dueDateEnd"/>');
      return false;
    }
  }
  if ( (myform.attributes1a.value == 'VersionNumber' && 
        !isAllDigits(myform.attributes1c.value)) || 
       (myform.attributes2a.value == 'VersionNumber' && 
        !isAllDigits(myform.attributes2c.value)) || 
       (myform.attributes3a.value == 'VersionNumber' && 
        !isAllDigits(myform.attributes3c.value)) || 
       (myform.attributes4a.value == 'VersionNumber' && 
        !isAllDigits(myform.attributes4c.value)) ) {
     alert('<bean:message bundle="appCommonRes" key="bp.contentservice.search.version.invalidValue"/>');
     return false;
  }

  return true;
}

function gotoPage(formName, pageNum) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
    thisForm.pageNum.value = pageNum;
    thisForm.submit();
  }
}

function onSubmit(myform, formname) {
  if (!validateForm(myform, formname)) return false;

  myform.submit();
  return true;
}

</script>

<html:form action="/contentFullSearch.do?action=search">
<html:hidden property="pageNum" value="1" />
<html:hidden property="filePath" />
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean:message bundle="appCommonRes"  key="bp.content.contentSearch"/>">
  <tr> 
  <td valign="top" width="100%">
		  
  <div class="pageTitle"><bean:message bundle="appCommonRes"  key="bp.content.contentSearch"/></div>
  
  <% 
   String actionParam = (String)request.getParameter("action");
   if (actionParam != null) {
  %>
  <div class="pageSubtitle">
    <span class="left"><bean:message  bundle="appCommonRes" key="bp.contentservice.search.searchResultFound" arg0="<%= totalCountNum %>" /></span>
    <span class="right">&nbsp;</span>
  </div> 
  <% } %>

  
  <div class="blockWrap">         
  <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean:message bundle="appCommonRes"  key="bp.content.contentSearch"/>">
         
  <!--start main content here-->
    <logic:equal name="searchResultView" property="fulltextSearchEnabled" value="true">   
      <tr>
        <td valign="top" wrap width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.fulltextQuery"/>:</td>
        <td valign="top" class="labelField" width="80%" colspan="2">
          <html:text name="searchResultView" property="fulltextQuery" maxlength="255" size="85" />
        </td>
      </tr>
    </logic:equal>
    <tr>
      <td valign="top" width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.contentName"/>: </td>
      <td valign="top" class="labelField" width="80%" colspan="2">
        <html:text name="searchResultView" property="contentName" maxlength="80" size="31" />
      </td>
    </tr>

    <tr>
      <td valign="top" width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.attributes"/>: </td>
      <td valign="top" class="labelField" width="80%" colspan="2" nowrap>
      <html:select name ="searchResultView" property="attributes1a" size="1">
        <html:option value=""></html:option>
        <html:option value="CheckedOutBy"><bean:message bundle="appCommonRes"  key="bp.content.checkedOutBy"/></html:option>
        <html:option value="CreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.author"/></html:option>
        <html:option value="VersionNumber"><bean:message bundle="appCommonRes"  key="bp.content.version"/></html:option>
        <html:option value="VersionCreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.modifiedBy"/></html:option>
      </html:select>
      <html:select name ="searchResultView" property="attributes1b" size="1">
        <html:option value="-1">&nbsp;</html:option>
        <html:option value="0"><bean:message bundle="appCommonRes"  key="bp.content.eq"/></html:option>
        <html:option value="1"><bean:message bundle="appCommonRes"  key="bp.content.neq"/></html:option>
        <html:option value="2"><bean:message bundle="appCommonRes"  key="bp.content.lt"/></html:option>
        <html:option value="3"><bean:message bundle="appCommonRes"  key="bp.content.lteq"/></html:option>
        <html:option value="4"><bean:message bundle="appCommonRes"  key="bp.content.gt"/></html:option>
        <html:option value="5"><bean:message bundle="appCommonRes"  key="bp.content.gteq"/></html:option>
      </html:select>
      <html:text name="searchResultView" property="attributes1c" maxlength="80" size="31" />&nbsp; <bean:message bundle="appCommonRes"  key="bp.content.and"/>
    </tr>

    <tr>
      <td valign="top" width="20%" class="label">&nbsp;</td>
      <td valign="top" class="labelField" width="80%" colspan="2" nowrap>
      <html:select name ="searchResultView" property="attributes2a" size="1">
        <html:option value=""></html:option>
        <html:option value="CheckedOutBy"><bean:message bundle="appCommonRes"  key="bp.content.checkedOutBy"/></html:option>
        <html:option value="CreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.author"/></html:option>
        <html:option value="VersionNumber"><bean:message bundle="appCommonRes"  key="bp.content.version"/></html:option>
        <html:option value="VersionCreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.modifiedBy"/></html:option>
      </html:select>
      <html:select name ="searchResultView" property="attributes2b" size="1">
        <html:option value="-1">&nbsp;</html:option>
        <html:option value="0"><bean:message bundle="appCommonRes"  key="bp.content.eq"/></html:option>
        <html:option value="1"><bean:message bundle="appCommonRes"  key="bp.content.neq"/></html:option>
        <html:option value="2"><bean:message bundle="appCommonRes"  key="bp.content.lt"/></html:option>
        <html:option value="3"><bean:message bundle="appCommonRes"  key="bp.content.lteq"/></html:option>
        <html:option value="4"><bean:message bundle="appCommonRes"  key="bp.content.gt"/></html:option>
        <html:option value="5"><bean:message bundle="appCommonRes"  key="bp.content.gteq"/></html:option>
      </html:select>
      <html:text name="searchResultView" property="attributes2c" maxlength="80" size="31" />&nbsp; <bean:message bundle="appCommonRes"  key="bp.content.and"/>
    </tr>

    <tr>
      <td valign="top" width="20%" class="label">&nbsp;</td>
      <td valign="top" class="labelField" width="80%" colspan="2" nowrap>
      <html:select name ="searchResultView" property="attributes3a" size="1">
        <html:option value=""></html:option>
        <html:option value="CheckedOutBy"><bean:message bundle="appCommonRes"  key="bp.content.checkedOutBy"/></html:option>
        <html:option value="CreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.author"/></html:option>
        <html:option value="VersionNumber"><bean:message bundle="appCommonRes"  key="bp.content.version"/></html:option>
        <html:option value="VersionCreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.modifiedBy"/></html:option>
      </html:select>
      <html:select name ="searchResultView" property="attributes3b" size="1">
        <html:option value="-1">&nbsp;</html:option>
        <html:option value="0"><bean:message bundle="appCommonRes"  key="bp.content.eq"/></html:option>
        <html:option value="1"><bean:message bundle="appCommonRes"  key="bp.content.neq"/></html:option>
        <html:option value="2"><bean:message bundle="appCommonRes"  key="bp.content.lt"/></html:option>
        <html:option value="3"><bean:message bundle="appCommonRes"  key="bp.content.lteq"/></html:option>
        <html:option value="4"><bean:message bundle="appCommonRes"  key="bp.content.gt"/></html:option>
        <html:option value="5"><bean:message bundle="appCommonRes"  key="bp.content.gteq"/></html:option>
      </html:select>
      <html:text name="searchResultView" property="attributes3c" maxlength="80" size="31" />&nbsp; <bean:message bundle="appCommonRes"  key="bp.content.and"/>
    </tr>

    <tr>
      <td valign="top" width="20%" class="label">&nbsp;</td>
      <td valign="top" class="labelField" width="80%" colspan="2" nowrap>
      <html:select name ="searchResultView" property="attributes4a" size="1">
        <html:option value=""></html:option>
        <html:option value="CheckedOutBy"><bean:message bundle="appCommonRes"  key="bp.content.checkedOutBy"/></html:option>
        <html:option value="CreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.author"/></html:option>
        <html:option value="VersionNumber"><bean:message bundle="appCommonRes"  key="bp.content.version"/></html:option>
        <html:option value="VersionCreatedBy"><bean:message bundle="appCommonRes"  key="bp.content.modifiedBy"/></html:option>
      </html:select>
      <html:select name ="searchResultView" property="attributes4b" size="1">
        <html:option value="-1">&nbsp;</html:option>
        <html:option value="0"><bean:message bundle="appCommonRes"  key="bp.content.eq"/></html:option>
        <html:option value="1"><bean:message bundle="appCommonRes"  key="bp.content.neq"/></html:option>
        <html:option value="2"><bean:message bundle="appCommonRes"  key="bp.content.lt"/></html:option>
        <html:option value="3"><bean:message bundle="appCommonRes"  key="bp.content.lteq"/></html:option>
        <html:option value="4"><bean:message bundle="appCommonRes"  key="bp.content.gt"/></html:option>
        <html:option value="5"><bean:message bundle="appCommonRes"  key="bp.content.gteq"/></html:option>
      </html:select>
      <html:text name="searchResultView" property="attributes4c" maxlength="80" size="31" />&nbsp;
    </tr>
    
    <tr>
      <td valign="middle" width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.contentCreationDate"/>:</td>
      <td valign="middle" width="10%" class="labelField" nowrap>  	      
        <html:checkbox property="includeCreateDateStart"/>
        <bean:message bundle="appCommonRes"  key="bp.content.from"/>:
      </td>
      <td valign="middle" width="70%" class="labelField" nowrap>	
        <bvhtml:date name="searchResultView" property="createDateStart" />
        <a href="JavaScript:datePopup(
          '<html:rewrite page="/cs/calendar.do"/>', 'contentFullSearchForm','createDateStart')">
          <img src="<%= ctxPath %>/ca/images/icons/calendar.gif" width="22" height="22" 
            alt="<bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.chooseDate" />" 
            border="0" align="absmiddle"/>
        </a>				  
      </td>
    </tr>
  
    <tr>
      <td valign="middle" width="20%" class="label">&nbsp;</td>
      <td valign="middle" width="10%" class="labelField" nowrap>  	      
        <html:checkbox property="includeCreateDateEnd"/>
        <bean:message bundle="appCommonRes"  key="bp.content.to"/>:
      </td>
      <td valign="middle" width="70%" class="labelField" nowrap>	
        <bvhtml:date name="searchResultView" property="createDateEnd" />
        <a href="JavaScript:datePopup(
          '<html:rewrite page="/cs/calendar.do"/>', 'contentFullSearchForm','createDateEnd')">
          <img src="<%= ctxPath %>/ca/images/icons/calendar.gif" width="22" height="22" 
            alt="<bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.chooseDate" />" 
            border="0" align="absmiddle"/>
        </a>				  
      </td>
    </tr>
  
    <tr>
      <td valign="middle" width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.contentModificationDate"/>:</td>
      <td valign="middle" width="10%" class="labelField" nowrap>  	      
        <html:checkbox property="includeModDateStart"/>
        <bean:message bundle="appCommonRes"  key="bp.content.from"/>:
      </td>
      <td valign="middle" width="70%" class="labelField" nowrap>	
        <bvhtml:date name="searchResultView" property="modDateStart" />
        <a href="JavaScript:datePopup(
          '<html:rewrite page="/cs/calendar.do"/>', 'contentFullSearchForm','modDateStart')">
          <img src="<%= ctxPath %>/ca/images/icons/calendar.gif" width="22" height="22" 
            alt="<bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.chooseDate" />" 
            border="0" align="absmiddle"/>
        </a>				  
      </td>
    </tr>
  
    <tr>
      <td valign="middle" width="20%" class="label">&nbsp;</td>
      <td valign="middle" width="10%" class="labelField" nowrap>  	      
        <html:checkbox property="includeModDateEnd"/>
        <bean:message bundle="appCommonRes"  key="bp.content.to"/>:
      </td>
      <td valign="middle" width="70%" class="labelField" nowrap>	
        <bvhtml:date name="searchResultView" property="modDateEnd" />
        <a href="JavaScript:datePopup(
          '<html:rewrite page="/cs/calendar.do"/>', 'contentFullSearchForm','modDateEnd')">
          <img src="<%= ctxPath %>/ca/images/icons/calendar.gif" width="22" height="22" 
            alt="<bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.chooseDate" />" 
            border="0" align="absmiddle"/>
        </a>				  
      </td>
    </tr>
        
    <tr>
      <td valign="top" width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.processModelName"/>: </td>
      <td valign="top" class="labelField" width="80%" colspan="2">
        <html:text name="searchResultView" property="procModelName" maxlength="80" size="31" />
      </td>
    </tr>
    
    <tr>
      <td valign="top" wrap width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.content.processInstanceName"/>:</td>
      <td valign="top" class="labelField" width="80%" colspan="2">
        <html:text name="searchResultView" property="procInstanceName" maxlength="80" size="31" />
      </td>
    </tr>


    <tr> 
      <td valign="top" width="20%" class="label"><bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.sortby"/></td>
      <td valign="top" class="labelField" width="80%" colspan="2">
        <html:select name ="searchResultView" property="sortBy" size="1">
        <html:option value=""><bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.option.nosort"/></html:option>
        <html:option value="contentName"><bean:message bundle="appCommonRes"  key="bp.content.contentName"/></html:option>
        <html:option value="version"><bean:message bundle="appCommonRes"  key="bp.content.version"/></html:option>
        <html:option value="contentObjectType"><bean:message bundle="appCommonRes"  key="bp.content.type"/></html:option>
        <html:option value="versionCreatedTime"><bean:message bundle="appCommonRes"  key="bp.content.modifiedOn"/></html:option>
        <html:option value="checkedOutBy"><bean:message bundle="appCommonRes"  key="bp.content.checkedOutBy"/></html:option>
        <html:option value="processInstanceName"><bean:message bundle="appCommonRes"  key="bp.content.processInstanceName"/></html:option>
        </html:select>
        &nbsp; &nbsp;<span class="label"><bean:message bundle="appCommonRes"  key="bp.process.processInstanceSearch.rows"/></span>
        <html:select name ="searchResultView" property="limitPerPage" size="1" >
        <html:option value="10">10</html:option>
        <html:option value="20">20</html:option>
        <html:option value="30">30</html:option>
        <html:option value="50">50</html:option>
        <html:option value="100">100</html:option>
        </html:select>
      </td>
    </tr>
        
  </table>
  <div class="pageButtonWrap" align="right">
   <input type="button" name="results" class="inputButton"  onClick="return onSubmit(this.form, 'contentFullSearchForm')"
                value="<bean:message bundle="appCommonRes"  key="button.showResults"/>">
  </div>  
      
  <br>
	  
<logic:match name="searchResultView" property="searchResultMsg" value="ShowResults">

  <div class="pageSubtitle">
    <span class="left"><bean:message  bundle="appCommonRes" key="bp.contentservice.search.searchResultFound" arg0="<%= totalCountNum %>" /></span>
    <span class="right">&nbsp;</span>
  </div>
    
  <table class="dataTable" border="0" cellspacing="1" cellpadding="2" width="100%" summary="<bean:message bundle="appCommonRes"  key="bp.content.searchResultList"/>">
  <tr class="listHeader"> 
    <th id="Content Name" align="left"><bean:message bundle="appCommonRes"  key="bp.content.contentName"/></th>
    <th id="Version" align="left"><bean:message bundle="appCommonRes"  key="bp.content.version"/></th>
    <th id="Type" align="left" nowrap><bean:message bundle="appCommonRes"  key="bp.content.type"/></th>
    <th id="Modified on" align="left" nowrap><bean:message bundle="appCommonRes"  key="bp.content.modifiedOn"/></th>
    <th id="Modified by" align="left" nowrap><bean:message bundle="appCommonRes"  key="bp.content.modifiedBy"/></th>
    <th id="Checked out by" align="left" nowrap><bean:message bundle="appCommonRes"  key="bp.content.checkedOutBy"/></th>
    <th id="Process Instance" align="left" nowrap><bean:message bundle="appCommonRes"  key="bp.content.processInstance"/></th>
  </tr>     
  
  <logic:equal name="resultSize" value="0">
  <tr class="listEven"> 
    <td colspan="7" valign="top" align="center"><bean:message bundle="appCommonRes"  key="bp.content.noContentFound"/></td>
  </tr>
  </logic:equal>

  <logic:iterate id="result" name="searchResultView" property="resultList" indexId="index">  
    <tr class='<%=index.intValue() %2 == 0 ? "listEven" : "listOdd"%>'>
      <td headers="Content Name" align="center">
      <logic:equal name="result" property="attachment" value="false">    
       <html:link page="/contentDetail.do?action=search" name="result" property="urlParams">
         <bean:write name="result" property="contentName"/>
       </html:link>
      </logic:equal>
      <logic:equal name="result" property="attachment" value="true"> 
	<a href="#" onclick='javascript:doAttachment(document.contentFullSearchForm,"<bean:write name='result' property='urlParams'/>")'> <bean:write name="result" property="contentName"/></a>
      </logic:equal>     
      </td>
      <td headers="Version"><bean:write name="result" property="version"/></td>
      <td headers="Type" align="center"><bean:write name="result" property="contentObjectType"/></td>
      <td headers="Modified on"><bean:write name="result" property="versionCreatedTime" formatKey="format.datetime.long"/></td>
      <td headers="Modified by"><bean:write name="result" property="versionCreatedBy"/></td>
      <td headers="Checked out by" align="center"><bean:write name="result" property="checkedOutBy"/></td>
      <td headers="Process Instance" align="center">
      <html:link page="/processInstance.do?" name="result" property="procUrlParams">
        <bean:write name="result" property="processInstanceName"/>
      </html:link>
      </td>
    </tr>
  </logic:iterate>

  </table>

</logic:match>

<logic:equal name="searchResultView" property="pagination" value="1"> 
   
   <% 
     Integer currentPageNumberInt = (Integer) PropertyUtils.getSimpleProperty(view, "currPageNum"); 
     Integer totalPageNumberInt = (Integer) PropertyUtils.getSimpleProperty(view, "totalPageNum"); 
   %>
   
  <div class="pagination">

  <logic:greaterThan name="searchResultView" property="currPageNum" value="1">
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('contentFullSearchForm', 1)"><bean:message bundle="appCommonRes"  key="bp.common.pagination.first"/></a>
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('contentFullSearchForm', <%= currentPageNumberInt.intValue()-1 %>)"><bean:message bundle="appCommonRes"  key="bp.common.pagination.previous"/></a>
  </logic:greaterThan>

  <bean:message bundle="appCommonRes"  key="bp.common.pagination.pageOf" arg0="<%= currentPageNumberInt.toString() %>" arg1="<%= totalPageNumberInt.toString() %>"/>

  <logic:lessThan name="searchResultView" property="currPageNum" value="<%= totalPageNumberInt.toString()%>">
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('contentFullSearchForm', <%= currentPageNumberInt.intValue()+1 %>)"><bean:message bundle="appCommonRes"  key="bp.common.pagination.next"/></a>
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('contentFullSearchForm', <%= totalPageNumberInt.intValue() %>)"><bean:message bundle="appCommonRes"  key="bp.common.pagination.last"/></a>
  </logic:lessThan>

  </div>

</logic:equal>
  </div>
 </td>
 </tr>
</table>
</html:form>
